﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iTunesLib;
using System.Collections.ObjectModel;
using MP3Ganizer.BusinessObject.Music;

namespace MP3Ganizer.BusinessObject.Services.IO
{
    class ITunesService
    {
        private List<IITFileOrCDTrack> _tracks;
        //private ObservableCollection<string> _artists;
        //private ObservableCollection<string> _albums;
        private iTunesApp _itunes;
        private IITLibraryPlaylist _mainLibrary;
        public ITunesService()
        {
            _tracks = new List<IITFileOrCDTrack>();
            //_artists = new ObservableCollection<string>();
            //_albums = new ObservableCollection<string>();
            // iTunes classes
            _itunes = new iTunesApp();
            _mainLibrary = _itunes.LibraryPlaylist;
        }

        public void Load()
        {
            
            IITTrackCollection tracks = _mainLibrary.Tracks;
            var myEnum = tracks.GetEnumerator();

            while (myEnum.MoveNext())
            {
                IITFileOrCDTrack currTrack = myEnum.Current as IITFileOrCDTrack;
                // is this a file track?
                if (currTrack != null && currTrack.Kind == ITTrackKind.ITTrackKindFile)
                {
                    _tracks.Add(currTrack);
                }
            }
        }



        private void TryToAdd(ICollection<string> infos, string info)
        {
            if (!string.IsNullOrEmpty(info as string) && !infos.Contains(info))
                infos.Add(info);
        }
    }
}
